JavaScript Beginners: Learn Java Script Programming Language, Basics Concept & Practice by Example by Digital Press Scorpio

JavaScript Beginners: Learn Java Script Programming Language, Basics Concept & Practice by Example by Digital Press Scorpio

Author:Digital Press , Scorpio [Digital Press , Scorpio]
Language: eng
Format: epub
Publisher: Scorpio Digital Press
Published: 2019-08-11T16:00:00+00:00


Chapter Three: An Introduction to Loops

Loops are for when you have to do a similar task multiple times. Say for example, you have to write the names of your guests who are coming to your event. How are you going to translate that into JavaScript? Sure, you can go ahead and try to set each name into a specific variable, but this will be very time consuming. It might work for you when there’re maybe ten or twenty guests, but how about when there are a hundred? You don’t want your arm to fall off right? Therefore, it is essential to learn the basics of “Loops”.

Loops in JavaScript simply enable a programmer to do a similar task repeatedly with very little effort.

For example, instead of writing:

Text += houses[0] + “<br>”

Text += houses[1] + “<br>”

Text += houses[2] + “<br>”

Text += houses[3] + “<br>”

You can just write:

for (i = 0; i<houses.length; i++) {

text += houses[i] + "<br>";

}



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.